"""Shopping URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
import xadmin
from django.contrib import admin
from django.urls import path, include
from django.views.static import serve
from rest_framework.documentation import include_docs_urls
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token

from Shopping.settings import MEDIA_ROOT
from app.goods.views import GoodsListViewSet, CategoryViewSet
# from rest_framework.authtoken import views
from app.trade.views import ShoppingCartViewset
from app.user_operation.views import UserFavViewset, AddressViewset
from app.users.views import SmsCodeViewset, UserViewset, LeavingMessageViewset

router = DefaultRouter()
# 配置goods的url, 自动生成路由和视图函数的对应关系。
"""
^goods/$ [name='goods-list'] 
^goods\.(?P<format>[a-z0-9]+)/?$ [name='goods-list'] 
^goods/(?P<pk>[^/.]+)/$ [name='goods-detail'] 
^goods/(?P<pk>[^/.]+)\.(?P<format>[a-z0-9]+)/?$ [name='goods-detail'] 
"""
router.register(r'goods', GoodsListViewSet, basename='goods')
router.register(r'categorys',CategoryViewSet,basename='categorys')
router.register(r'code', SmsCodeViewset, basename="code")
router.register(r'users', UserViewset, basename="users")
# 配置用户收藏的url
router.register(r'userfavs', UserFavViewset, basename="userfavs")
router.register(r'messages', LeavingMessageViewset, basename="messages")
router.register(r'address', AddressViewset, basename="address")
router.register(r'shopcart', ShoppingCartViewset, basename="shopcart")

urlpatterns = [
    # path('admin/', admin.site.urls),
    path('xadmin/',xadmin.site.urls),
    path('ueditor/',include('DjangoUeditor.urls')),
    # 文件, 通过路由的方式访问用户上传的文件/图片/视频.......
    path('media/<path:path>', serve, {'document_root': MEDIA_ROOT}),
    # path('goods/',GoodsListView.as_view()),
    path('api-auth/',include('rest_framework.urls')),
    # drf文档，title自定义
    path('docs', include_docs_urls(title='Fan RESTful Docs')),
    # token
    # path('api-token-auth/', views.obtain_auth_token)
    # jwt的token认证接口
    path('jwt-auth/', obtain_jwt_token)
    # 商品列表页, 删除前两种商品列表页的url配置.
    # path('goods/', GoodsListView.as_view(), name='goods-list-rest')

]
# 将DefaultRouter注册的路由和视图函数对应关系添加到urlpatterns里面。
urlpatterns += router.urls
